
import sheetmanage from './sheetmanage';
import server from './server';
import { sheetselectlistitemHTML, sheetselectlistHTML, keycode, sheetconfigHTML } from './constant';
import {
    replaceHtml,
    mouseclickposition
} from '../utils/util';
import { getSheetIndex } from '../methods/get';
import { isEditMode } from '../global/validate';
import formula from '../global/formula';
import cleargridelement from '../global/cleargridelement';
import tooltip from '../global/tooltip';
import { selectTextDom } from '../global/cursorPos';
import locale from '../locale/locale';
import Store from '../store';
import luckysheetConfigsetting from './luckysheetConfigsetting';
import { getCurrentSheetIndex, pagerInit } from '../global/api';
import method from '../global/method';

// 表格底部名称栏区域 相关事件（增、删、改、隐藏显示、颜色等等）
let isInitialSheetConfig = false, luckysheetcurrentSheetitem = null, jfdbclicklagTimeout = null, oldSheetFileName = "";
export function rightClickVerify (menuItem, index) {
    const  rules = menuItem.rules || [];
    let res = true;
    rules.forEach((rule) => {
        switch (rule) {
        case 'atleastonesheet':
            if (Store.luckysheetfile.length <= 1) res = false;
            break;
        default:
            break;
        }
    });
    return res;
}
function showsheetconfigmenu () {
    if (!isInitialSheetConfig) {
        isInitialSheetConfig = true;
        const _locale = locale();
        let locale_toolbar = _locale.toolbar;
        const locale_button = _locale.button;
        setTimeout(() => {
            $("#luckysheetsheetconfigcolorur").spectrum({
                showPalette: true,
                showPaletteOnly: true,
                preferredFormat: "hex",
                clickoutFiresChange: false,
                showInitial: true,
                showInput: true,
                flat: true,
                hideAfterPaletteSelect: true,
                showSelectionPalette: true,
                maxPaletteSize: 8,
                maxSelectionSize: 8,
                cancelText: locale_button.cancel,
                chooseText: locale_button.confirm,
                togglePaletteMoreText: locale_toolbar.customColor,
                togglePaletteLessText: locale_toolbar.collapse,
                togglePaletteOnly: true,
                clearText: locale_toolbar.clearText,
                color: luckysheetConfigsetting.defaultCellColor,
                noColorSelectedText: locale_toolbar.noColorSelectedText,
                localStorageKey: "spectrum.textcolor" + server.gridKey,
                palette: [["#000", "#444", "#666", "#999", "#ccc", "#eee", "#f3f3f3", "#fff"],
                    ["#f00", "#f90", "#ff0", "#0f0", "#0ff", "#00f", "#90f", "#f0f"],
                    ["#f4cccc", "#fce5cd", "#fff2cc", "#d9ead3", "#d0e0e3", "#cfe2f3", "#d9d2e9", "#ead1dc"],
                    ["#ea9999", "#f9cb9c", "#ffe599", "#b6d7a8", "#a2c4c9", "#9fc5e8", "#b4a7d6", "#d5a6bd"],
                    ["#e06666", "#f6b26b", "#ffd966", "#93c47d", "#76a5af", "#6fa8dc", "#8e7cc3", "#c27ba0"],
                    ["#c00", "#e69138", "#f1c232", "#6aa84f", "#45818e", "#3d85c6", "#674ea7", "#a64d79"],
                    ["#900", "#b45f06", "#bf9000", "#38761d", "#134f5c", "#0b5394", "#351c75", "#741b47"],
                    ["#600", "#783f04", "#7f6000", "#274e13", "#0c343d", "#073763", "#20124d", "#4c1130"]],
                change: function (color) {
                    let $input = $(this);
                    if (color != null) {
                        color = color.toHexString();
                    } else {
                        color = "#ffffff";
                    }

                    let oldcolor = null;
                    if (luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").length > 0) {
                        oldcolor = luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").css("background-color");
                    }

                    luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").remove();
                    const colorHTML = `<div class="luckysheet-sheets-item-color" style=" position: absolute; width: 100%; height: 3px; bottom: 2px; left: 0px; background-color: ${color || 'var(--ux-primary-color, #555FFF)'};"></div>`;
                    luckysheetcurrentSheetitem.append(colorHTML);
                    let index = getSheetIndex(Store.currentSheetIndex);
                    Store.luckysheetfile[index].color = color;
                    server.saveParam("all", Store.currentSheetIndex, color, { "k": "color" });
                    // $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
                    $('#luckysheetsheetconfigcolor_sub').hide();
                    $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
                    if (Store.clearjfundo) {
                        let redo = {};
                        redo.type = "sheetColor";
                        redo.sheetIndex = Store.currentSheetIndex;

                        redo.oldcolor = oldcolor;
                        redo.color = color;

                        Store.jfundo.length = 0;
                        Store.jfredo.push(redo);
                    }
                }
            });

            $("#luckysheetsheetconfigcolorreset").click(function () {
                let oldcolor = null;
                if (luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").length > 0) {
                    oldcolor = luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").css("background-color");
                }

                luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").remove();
                let index = getSheetIndex(Store.currentSheetIndex);
                Store.luckysheetfile[index].color = null;
                server.saveParam("all", Store.currentSheetIndex, null, { "k": "color" });

                if (Store.clearjfundo) {
                    let redo = {};
                    redo.type = "sheetColor";
                    redo.sheetIndex = Store.currentSheetIndex;

                    redo.oldcolor = oldcolor;
                    redo.color = null;

                    Store.jfundo.length = 0;
                    Store.jfredo.push(redo);
                }
            });
            $('#luckysheetsheetconfigcolor').click(function (e) {
                e.stopPropagation();
            });
            $('#luckysheetsheetconfigcolor_sub, #luckysheet-rightclick-sheet-menu').on("contextmenu", function (e) {
                e.preventDefault();
            });
        }, 1);
    }
    let index = getSheetIndex(Store.currentSheetIndex);
    $("#luckysheetsheetconfigcolorur").spectrum("option", "showPaletteOnly", true);
    if (Store.luckysheetfile[index].color != null && Store.luckysheetfile[index].color.length > 0) {
        $("#luckysheetsheetconfigcolorur").spectrum("set", Store.luckysheetfile[index].color);
    }

    $("#luckysheetsheetconfigcolorur").parent().find("span, div, button, input, a").addClass("luckysheet-mousedown-cancel");

    // 如果全部按钮设置了隐藏，则不显示
    const config = luckysheetConfigsetting.sheetRightClickConfig;
    // if(!config.delete && !config.copy && !config.rename && !config.color && !config.hide && !config.move){
    if (Object.values(config).every(ele => !ele)) {
        return;
    }
    config.forEach((c, index) => {
        let verify = rightClickVerify(c, index);
        let node = $(`.luckysheetsheetconfigsub[data-menuindex="${index}"]`);
        if (node) {
            if (verify) {
                node.removeClass('no-permision');
            } else {
                node.addClass('no-permision');
            }
        }
    });
    mouseclickposition($("#luckysheet-rightclick-sheet-menu"), luckysheetcurrentSheetitem.offset().left + luckysheetcurrentSheetitem.width(), luckysheetcurrentSheetitem.offset().top - 18, "leftbottom");
}

let luckysheetsheetrightclick = function ($t, $cur, e) {
    clearTimeout(jfdbclicklagTimeout);
    if ($cur.hasClass("luckysheet-sheets-item-name") && $cur.attr("contenteditable") == "true") {
        return;
    }
    if (formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton()) {
        setTimeout(function () {
            formula.setCaretPosition(formula.rangeSetValueTo.get(0), 0, formula.rangeSetValueTo.text().length);
            formula.createRangeHightlight();
            $("#luckysheet-input-box-index").find(".luckysheet-input-box-index-sheettxt").remove().end().prepend("<span class='luckysheet-input-box-index-sheettxt'>" + sheetmanage.getSheetName(formula.rangetosheet) + "!</span>").show();
            $("#luckysheet-input-box-index").css({ "left": $("#luckysheet-input-box").css("left"), "top": (parseInt($("#luckysheet-input-box").css("top")) - 20) + "px", "z-index": $("#luckysheet-input-box").css("z-index") });
        }, 1);
    } else {
        // 保存正在编辑的单元格内容
        if (parseInt($("#luckysheet-input-box").css("top")) > 0) {
            formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]);
        }

        $("#luckysheet-input-box").removeAttr("style");
        $("#luckysheet-formula-functionrange .luckysheet-formula-functionrange-highlight").remove();
    }

    $t.addClass("luckysheet-sheets-item-active");
    cleargridelement(e);
    sheetmanage.changeSheet($t.data("index"));
    if ($cur.css('cursor') !== 'pointer') {
        $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
    }

    if (e.which == "3" || $cur.css('cursor') === 'pointer') {
        luckysheetcurrentSheetitem = $cur.closest(".luckysheet-sheets-item");
        setTimeout(() => {
            showsheetconfigmenu();
        });
    }
};

export function initialSheetBar () {
    const _locale = locale();
    const locale_sheetconfig = _locale.sheetconfig;
    isInitialSheetConfig = false;

    $("#luckysheet-sheet-area").on("mousedown", "div.luckysheet-sheets-item", function (e) {
        if (isEditMode()) {
            // alert("非编辑模式下不允许该操作！");
            return;
        }

        let $t = $(this), $cur = $(e.target), $item = $cur.closest(".luckysheet-sheets-item");

        if (e.which == "3" || $cur.hasClass('fa-sort-desc')) {
            setTimeout(() => {
                luckysheetsheetrightclick($t, $cur, e);
                luckysheetcurrentSheetitem = $item;
                showsheetconfigmenu();
            }, 0);
        }

        if ($item.hasClass("luckysheet-sheets-item-active") && $item.find(".luckysheet-sheets-item-name").attr("contenteditable") == "false") {
            jfdbclicklagTimeout = setTimeout(function () {
                Store.luckysheet_sheet_move_status = true;
                Store.luckysheet_sheet_move_data = {};
                Store.luckysheet_sheet_move_data.widthlist = [];

                $("#luckysheet-sheet-area div.luckysheet-sheets-item:visible").each(function (i) {
                    if (i == 0) {
                        Store.luckysheet_sheet_move_data.widthlist.push(parseInt($(this).outerWidth()));
                    } else {
                        Store.luckysheet_sheet_move_data.widthlist.push(parseInt($(this).outerWidth()) + Store.luckysheet_sheet_move_data.widthlist[i - 1]);
                    }
                });

                Store.luckysheet_sheet_move_data.curindex = $("#luckysheet-sheet-area div.luckysheet-sheets-item").index($item);
                let x = e.pageX;
                Store.luckysheet_sheet_move_data.curleft = x - $item.offset().left;
                Store.luckysheet_sheet_move_data.pageX = x;
                Store.luckysheet_sheet_move_data.activeobject = $item;
                Store.luckysheet_sheet_move_data.cursorobject = $cur;
                let $itemclone = $item.clone().css("visibility", "hidden").attr("id", "luckysheet-sheets-item-clone");
                $item.after($itemclone);
                $item.css({ "position": "absolute", "opacity": 0.8, "cursor": "move", "transition": "initial", "z-index": 10 });
            }, 200);
        }
    }).on("click", "div.luckysheet-sheets-item", function (e) {
        if (isEditMode()) {
            // alert("非编辑模式下不允许该操作！");
            return;
        }

        let $t = $(this), $cur = $(e.target);
        luckysheetsheetrightclick($t, $cur, e);
        server.keepHighLightBox();
    });

    let luckysheetsheetnameeditor = function ($t) {
        if (Store.allowEdit === false) {
            return;
        }
        $t.attr("contenteditable", "true").addClass("luckysheet-mousedown-cancel").data("oldtxt", $t.text());

        setTimeout(function () {
            selectTextDom($t.get(0));
        }, 1);
    };

    $("#luckysheet-sheet-area").on("dblclick", "span.luckysheet-sheets-item-name", function (e) {
        luckysheetsheetnameeditor($(this));
    });

    let compositionFlag = true;
    $("#luckysheet-sheet-area").on("compositionstart", "span.luckysheet-sheets-item-name",  () => compositionFlag = false);
    $("#luckysheet-sheet-area").on("compositionend", "span.luckysheet-sheets-item-name", () => compositionFlag = true);
    $("#luckysheet-sheet-area").on("input", "span.luckysheet-sheets-item-name", function () {
        if (Store.allowEdit === false) {
            return;
        }

        if (Store.limitSheetNameLength === false) {
            return;
        }

        let maxLength = Store.defaultSheetNameMaxLength;
        if (maxLength  === 0) {
            return;
        }

        setTimeout(() => {
            if (compositionFlag) {
                if ($(this).text().length >= maxLength) {  /* 检查：值是否越界 */
                    setTimeout(() => {
                        $(this).text($(this).text().substring(0, maxLength));

                        let range = window.getSelection();
                        range.selectAllChildren(this);
                        range.collapseToEnd();
                    }, 0);
                }
            }
        }, 0);
    });

    $("#luckysheet-sheet-area").on("blur", "span.luckysheet-sheets-item-name", function (e) {
        if (Store.allowEdit === false) {
            return;
        }

        let $t = $(this);
        let txt = $t.text(), oldtxt = $t.data("oldtxt");
        if ($(this).text().trim().length === 0) {
            // tooltip.info("", locale_sheetconfig.sheetNamecannotIsEmptyError);
            $t.text(oldtxt).attr("contenteditable", "false");
            return;
        }

        if (txt.length > 31 || txt.charAt(0) == "'" || txt.charAt(txt.length - 1) == "'" || /[：\:\\\/？\?\*\[\]]+/.test(txt)) {
            tooltip.info("", locale_sheetconfig.sheetNameSpecCharError);
            $t.text(oldtxt).attr("contenteditable", "false");
            return;
        }

        let index = getSheetIndex(Store.currentSheetIndex);
        for (let i = 0; i < Store.luckysheetfile.length; i++) {
            if (index != i && Store.luckysheetfile[i].name == txt) {
                if (isEditMode()) {
                    Store.message && Store.message.error(locale_sheetconfig.tipNameRepeat);
                } else {
                    Store.message && Store.message.error(locale_sheetconfig.tipNameRepeat);
                }
                $t.text(oldtxt).attr("contenteditable", "false");
                return;
            }
        }

        sheetmanage.sheetArrowShowAndHide();

        Store.luckysheetfile[index].name = txt;
        server.saveParam("all", Store.currentSheetIndex, txt, { "k": "name" });

        $t.attr("contenteditable", "false").removeClass("luckysheet-mousedown-cancel");

        if (Store.clearjfundo) {
            let redo = {};
            redo.type = "sheetName";
            redo.sheetIndex = Store.currentSheetIndex;

            redo.oldtxt = oldtxt;
            redo.txt = txt;

            Store.jfundo.length = 0;
            Store.jfredo.push(redo);
        }
        // 钩子： sheetEditNameAfter
        method.createHookFunction('sheetEditNameAfter', {
            i: Store.luckysheetfile[index].index,
            oldName: oldtxt,
            newName: txt
        });
    });

    $("#luckysheet-sheet-area").on("keydown", "span.luckysheet-sheets-item-name", function (e) {
        if (Store.allowEdit === false) {
            return;
        }
        let kcode = e.keyCode;
        let $t = $(this);
        if (kcode == keycode.ENTER) {
            let index = getSheetIndex(Store.currentSheetIndex);
            oldSheetFileName = Store.luckysheetfile[index].name || oldSheetFileName;
            Store.luckysheetfile[index].name = $t.text();
            $t.attr("contenteditable", "false");
        }
    });

    $("#luckysheetsheetconfigrename").click(function () {
        let $name = luckysheetcurrentSheetitem.find("span.luckysheet-sheets-item-name");
        // 钩子 sheetEditNameBefore
        if (!method.createHookFunction('sheetEditNameBefore', { i: luckysheetcurrentSheetitem.data('index'), name: $name.text() })) {
            return;
        }
        luckysheetsheetnameeditor(luckysheetcurrentSheetitem.find("span.luckysheet-sheets-item-name"));
        $("#luckysheet-input-box").removeAttr("style");
        $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
    });

    $(".luckysheetsheetconfigsub").click(function () {
        let index = $(this).data('menuindex');
        const menuItem = luckysheetConfigsetting.sheetRightClickConfig[index];
        let $name = luckysheetcurrentSheetitem.find("span.luckysheet-sheets-item-name");
        const verify = rightClickVerify(menuItem, index);
        if (!verify) return;
        let order = getSheetIndex(luckysheetcurrentSheetitem.data('index'));
        menuItem.onClick(order, $name.text());
        $("#luckysheet-input-box").removeAttr("style");
        $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
    });

    $("#luckysheetsheetconfigshow").click(function () {
        $("#luckysheet-sheets-m").click();
        $("#luckysheet-input-box").removeAttr("style");
        $("#luckysheet-rightclick-sheet-menu").hide();
    });

    $("#luckysheetsheetconfigmoveleft").click(function () {
        if (luckysheetcurrentSheetitem.prevAll(":visible").length > 0) {
            luckysheetcurrentSheetitem.insertBefore(luckysheetcurrentSheetitem.prevAll(":visible").eq(0));
            sheetmanage.reOrderAllSheet(true);
        }
        $("#luckysheet-input-box").removeAttr("style");
        $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
    });

    $("#luckysheetsheetconfigmoveright").click(function () {
        if (luckysheetcurrentSheetitem.nextAll(":visible").length > 0) {
            luckysheetcurrentSheetitem.insertAfter(luckysheetcurrentSheetitem.nextAll(":visible").eq(0));
            sheetmanage.reOrderAllSheet(true);
        }
        $("#luckysheet-input-box").removeAttr("style");
        $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
    });

    $("#luckysheetsheetconfigdelete").click(function (e) {
        $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
        method.createHookFunction('deleteSheet', luckysheetcurrentSheetitem.data("index"));
        // if ($("#luckysheet-sheet-container-c .luckysheet-sheets-item:visible").length <= 1) {
        //     if (isEditMode()) {
        //         alert(locale_sheetconfig.noMoreSheet);
        //     } else {
        //         tooltip.info(locale_sheetconfig.noMoreSheet, "");
        //     }

        //     return;
        // }

        // let index = getSheetIndex(Store.currentSheetIndex);

        // tooltip.confirm(locale_sheetconfig.confirmDelete + "【" + Store.luckysheetfile[index].name + "】？", "<span style='color:#9e9e9e;font-size:12px;'>" + locale_sheetconfig.redoDelete + "</span>", function () {
        //     sheetmanage.deleteSheet(luckysheetcurrentSheetitem.data("index"));
        // }, null);

        // $("#luckysheet-input-box").removeAttr("style");
    });

    $("#luckysheetsheetconfigcopy").click(function (e) {
        sheetmanage.copySheet(luckysheetcurrentSheetitem.data("index"), e);
        $("#luckysheet-input-box").removeAttr("style");
        $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
    });

    $("#luckysheetsheetconfighide").click(function () {
        if ($("#luckysheet-sheet-area div.luckysheet-sheets-item:visible").length == 1) {
            if (isEditMode()) {
                alert(locale_sheetconfig.noHide);
            } else {
                tooltip.info("", locale_sheetconfig.noHide);
            }
            return;
        }
        sheetmanage.setSheetHide(luckysheetcurrentSheetitem.data("index"));
        $("#luckysheet-input-box").removeAttr("style");
        $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
    });

    $("#luckysheet-sheets-add").click(function (e) {
        const hideAllLine = !method.createHookFunction('addNewSheet');
        // 保存正在编辑的单元格内容
        if (parseInt($("#luckysheet-input-box").css("top")) > 0) {
            formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]);
        }

        sheetmanage.addNewSheet(e, null, null, !hideAllLine);
        sheetmanage.locationSheet();
        let order = getSheetIndex(Store.currentSheetIndex);
        method.calContentCoordinate(Store.currentSheetIndex, [], Store.luckysheetfile[order].celldata);
        $("#luckysheet-input-box").removeAttr("style");
    });

    let sheetscrollani = null, sheetscrollstart = 0, sheetscrollend = 0, sheetscrollstep = 150;
    $("#luckysheet-sheets-leftscroll").click(function () {
        let $c = $("#luckysheet-sheet-container-c");
        sheetscrollstart = $c.scrollLeft();
        sheetscrollend = $c.scrollLeft() - sheetscrollstep;

        if (sheetscrollend <= 0) {
            $("#luckysheet-sheet-container .docs-sheet-fade-left").hide();
        }
        $("#luckysheet-sheet-container .docs-sheet-fade-right").show();

        clearInterval(sheetscrollani);
        sheetscrollani = setInterval(function () {
            sheetscrollstart -= 4;
            $c.scrollLeft(sheetscrollstart);
            if (sheetscrollstart <= sheetscrollend) {
                clearInterval(sheetscrollani);
            }
        }, 1);
    });

    $("#luckysheet-sheets-rightscroll").click(function () {
        let $c = $("#luckysheet-sheet-container-c");
        sheetscrollstart = $c.scrollLeft();
        sheetscrollend = $c.scrollLeft() + sheetscrollstep;

        if (sheetscrollstart > 0) {
            $("#luckysheet-sheet-container .docs-sheet-fade-right").hide();
        }
        $("#luckysheet-sheet-container .docs-sheet-fade-left").show();

        clearInterval(sheetscrollani);
        sheetscrollani = setInterval(function () {
            sheetscrollstart += 4;
            $c.scrollLeft(sheetscrollstart);
            if (sheetscrollstart >= sheetscrollend) {
                clearInterval(sheetscrollani);
            }
        }, 1);
    });

    let initialOpenSheet = true;
    $("#luckysheet-sheets-m").click(function (e) {
        // 保存正在编辑的单元格内容
        if (parseInt($("#luckysheet-input-box").css("top")) > 0) {
            formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]);
        }

        $("#luckysheet-sheet-list").html("");

        let item = "";
        for (let i = 0; i < Store.luckysheetfile.length; i++) {
            let f = Store.luckysheetfile[i], icon = '', style = "";
            if (f.status == 1) {
                icon = '<i class="fa fa-check" aria-hidden="true"></i>';
            }

            if (f.hide == 1) {
                icon = '<i class="fa fa-low-vision" aria-hidden="true"></i>';
                style += "color:#BBBBBB;";
            }

            if (f.color != null && f.color.length > 0) {
                style += "border-right:4px solid " + f.color + ";";
            }

            item += replaceHtml(sheetselectlistitemHTML, { "index": f.index, "name": f.name, "icon": icon, "style": style });
        }

        if (initialOpenSheet) {
            $("#" + Store.container).append(replaceHtml(sheetselectlistHTML, { "item": item }));
            $("#luckysheet-sheet-list").on("click", ".luckysheet-cols-menuitem", function (e) {
                if (isEditMode()) {
                    // tooltip.info("提示", "图表编辑模式下不允许该操作！");
                    alert(locale_sheetconfig.chartEditNoOpt);
                    return;
                }

                let $item = $(this), index = $item.data("index");

                if ($item.data("index") != Store.currentSheetIndex) {
                    sheetmanage.setSheetShow(index);
                    sheetmanage.locationSheet();
                }
                server.keepHighLightBox();
            });

            initialOpenSheet = false;
        } else {
            $("#luckysheet-sheet-list").html(item);
        }

        let $t = $("#luckysheet-sheet-list");

        let left = $(this).offset().left - $('#' + Store.container).offset().left;
        let bottom = $(this).height() + $('#luckysheet-sta-content').height() + 12;
        $t.css({ left: left + 'px', bottom: bottom + 'px' }).show();
        $("#luckysheet-input-box").removeAttr("style");
    });

    // 初始化分页器
    if (luckysheetConfigsetting.pager) {
        pagerInit(luckysheetConfigsetting.pager);
    }
}
